home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBOpen.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.0 KB  |  78 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBOpen [activeOrPassive] -- Open the connection, either proactively (activeOrPassive is "active")
  3.         or for listening (activeOrPassive is "passive").
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBOpen.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2755 -sn Main=CTBOpen ∂
  9.             CTBOpen.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBOpen }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBOpen(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBOpen(paramPtr);
  36.     end;
  37.  
  38. procedure CTBOpen(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var doActive: boolean;
  43.         sizes: CMBufferSizes;
  44.         status: CMStatFlags;
  45.  
  46.     procedure Fail(errMsg: Str255); { set theResult and quit }
  47.         begin
  48.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  49.             exit(CTBOpen);
  50.         end;
  51.  
  52.     begin
  53.         { Check the parameter count. }
  54.         if paramPtr^.paramCount > 1 then Fail('Invalid parameter count');
  55.  
  56.         { Figure out whether to open actively or passively. }
  57.         if not ParmPresent(1) then doActive := true
  58.         else if (Chr(paramPtr^.params[1]^^) = 'p') or (Chr(paramPtr^.params[1]^^) = 'P') then
  59.             doActive := false
  60.         else doActive := true;
  61.  
  62.         { Make sure the Comm Toolbox is available. }
  63.         CTBReady;
  64.         { And there's a current connection tool. }
  65.         EnsurePresent(connectionTool);
  66.  
  67.         { Check that we don't already have an open or opening connection. }
  68.         FailOSErr(CMStatus(Globals^^.connHand,sizes,status));
  69.         if BAnd(status,cmStatusOpen+cmStatusOpening) = 0 then
  70.             begin
  71.                 { Open. }
  72.                 if doActive then FailOSErr(CMOpen(Globals^^.connHand,true,nil,-1))
  73.                 else FailOSErr(CMListen(Globals^^.connHand,true,nil,-1));
  74.             end;
  75.     end;
  76.  
  77. end.
  78.